<#include "/template/_ListPage.html" /> <#assign title="角色管理"> <@center>
<div id="tb" style="height: auto">

	<div style="margin-bottom: 5px; border-bottom: 1px solid #ddd;">
		<form id="fm" method="post" action="${root!}/framerole/add">
			角色类别: <select id="roleType" name="FrameRole.roleTypeId"
				style="width: 80px"
				data-options="valueField:'id',  
                    textField:'roleTypeName'"></select>角色名称:
			<input name="FrameRole.roleName" style="width: 80px">排序号: <input
				name="FrameRole.order" type="number" style="width: 80px" value="0"> <a
				href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true"
				onclick="addRole();">新增角色</a> <a href="#" class="easyui-linkbutton"
				onclick="deleteRole()"
				data-options="plain:true,iconCls:'icon-cancel'">删除选中</a>
		</form>
	</div>
</div>

<table id="dg" toolbar="#tb">
	<thead>
		<tr>
			<th data-options="field:'ck',checkbox:true"></th>
			<th data-options="field:'roleTypeName',width:0.2">角色类别</th>
			<th data-options="field:'roleName',width:0.2,formatter:editName">角色名称</th>
			<th data-options="field:'order',width:0.2">排序值</th>
			<th data-options="field:'id',hidden:true"></th>
		</tr>
	</thead>
</table>


<script type="text/javascript">

$(function(){
    $('#roleType').combobox({
        url:'${root!}/framerole/getRoleType',
        panelHeight:'auto'
     });
    
	$('#dg').datagrid({  
	    url:'${root!}/framerole/table',
	    rownumbers:true,
	    pagination:true,
	    fitColumns: true,/*自动扩大或缩小列的尺寸以适应表格的宽度并且防止水平滚动*/
	    pageSize : ${tableSize!},
	    onDblClickRow:function(){
	    	editRoleType();
		},
		fit:true,
		checkbox:true,
		singleSelect:true,
		selectOnCheck:false
	});
});

function editRole(id_){
	var id = id_?id_:$('#dg').datagrid("getSelected").id;
	OpenDialogRefresh("${root!}/framerole/edit/"+id,"","500","500");
	
}

function editName(val,row){
	return '<a href="#" onclick="editRole(\''+row.id+'\')">'+val+'</a>';
}

function addRole(){
	$('#fm').form('submit',{
		success:function(msg){
	        Alert.info(msg,"系统消息",'refresh');
	    }
	});
}

function deleteRole(){
	var rows = $('#dg').datagrid("getChecked");
	if(rows.length==0){
		alert("未选择数据");
	}else{
		var ids=StringUtil.array2Str(rows,"id",";");
		$.ajax({
			url:"${root!}/framerole/delete?ids="+ids,
			type:"GET",
			dataType:"json",
			success:function(){
				window.location=window.location.href.replace("#","");
			}
		});
	}
}
</script>
</@center>
